package com.ja.util;

import com.ja.enumall.*;
import com.ja.util.pojoenum.*;


import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by 11936 on 2019/4/25.
 */

@RestController
@CrossOrigin
@RequestMapping("metadata")
public class PullDownMap {
    public final static String SUBCLASSSTATUS = "subClassStatus";
    public final static String INQUIRYSTATUS = "inquiryStatus";
    public final static String TYPE = "type";
    public final static String ISTAX = "isTax";
    public final static String CURRENCYCODE = "currencyCode";

    @PostMapping("getPullDownList")
    @CrossOrigin
    public ResultVo getPullDownList(@RequestBody List<String> methodKey){
        //放入本地所有的下拉列表的key
        List<String> pullKey = new ArrayList<>();
        pullKey.add(SUBCLASSSTATUS);
        pullKey.add(INQUIRYSTATUS);
        pullKey.add(TYPE);
        pullKey.add(ISTAX);
        pullKey.add(CURRENCYCODE);

        //去工厂里找我需要的下拉列表
        HashMap<String, List> hashMap =  getAddKey(pullKey);
        //常见一个新的hashMap
        HashMap<String, List> newHashMap = new HashMap<>();

        //将需要的下拉列表赋值给新的newHashMap
        for (String s : methodKey){
            if(hashMap.containsKey(s)){
                newHashMap.put(s, hashMap.get(s));
            }
        }
        return ResultBuildVo.success(newHashMap);
    }

    private HashMap<String,List> getAddKey(List<String> pullKey) {
        HashMap<String, List> hashMap = new HashMap<>();
        if(pullKey.contains(SUBCLASSSTATUS)){
            List<StatusDown> newList = new ArrayList<>();
            for (int i = StatusEnum.values().length-1; i >= 0; i--){
                newList.add(new StatusDown(StatusEnum.getStatusName(i), i));
            }
            hashMap.put(SUBCLASSSTATUS, newList);
        }

        if(pullKey.contains(INQUIRYSTATUS)){
            List<InquiryStatus> newList = new ArrayList<>();
            for (int i = 0; i < InquiryStatusEnum.values().length; i++){
                newList.add(new InquiryStatus(InquiryStatusEnum.getStatusName(i), i));
            }
            hashMap.put(INQUIRYSTATUS, newList);
        }

        if(pullKey.contains(TYPE)){
            List<Type> newList = new ArrayList<>();
            for (int i = 0; i < TypeEnum.values().length; i++){
                newList.add(new Type(TypeEnum.getStatusName(i), i));
            }
            hashMap.put(TYPE, newList);
        }

        if(pullKey.contains(ISTAX)){
            List<IsTax> newList = new ArrayList<>();
            for (int i = 0; i < IsTaxEnum.values().length; i++){
                newList.add(new IsTax(IsTaxEnum.getStatusName(i), i));
            }
            hashMap.put(ISTAX, newList);
        }

        if(pullKey.contains(CURRENCYCODE)){
            List<CurrencyCode> newList = new ArrayList<>();
            for (int i = 0; i < CurrencyCodeEnum.values().length; i++){
                newList.add(new CurrencyCode(CurrencyCodeEnum.getStatusName(i), i));
            }
            hashMap.put(CURRENCYCODE, newList);
        }
        return hashMap;
    }
}
